package com.foreveredu.propms.persist.hibernate;

import java.util.List;

import com.foreveredu.propms.domain.ChargeItem;
import com.foreveredu.propms.persist.IChargeItemDao;

public class HibernateChargeItemDao extends HibernateAbstractDao<ChargeItem, Integer> implements IChargeItemDao {

	private static final long serialVersionUID = 1L;
	
	public HibernateChargeItemDao() {
		super(ChargeItem.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public ChargeItem findByName(String name) {
		List<ChargeItem> chargeItemList = this.getHibernateTemplate().find("from ChargeItem ci where ci.name=?", name);
		ChargeItem chargeItem = null;
		if (chargeItemList != null && chargeItemList.size() > 0) {
			chargeItem = chargeItemList.get(0);
		}
		return chargeItem;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public ChargeItem findChargeItemByItemId(String itemId) {
		List<ChargeItem> ChargeItemList = this.getHibernateTemplate().find("from ChargeItem ci where ci.itemId= ?", itemId);
		ChargeItem ChargeItem = null;
		if (ChargeItemList != null && ChargeItemList.size() > 0) {
			ChargeItem = ChargeItemList.get(0);
		}
		return ChargeItem;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ChargeItem> findChargeItemsByType(int type) {
		List<ChargeItem> ChargeItemList = this.getHibernateTemplate().find("from ChargeItem ci where ci.type= ?", type);
		
		return ChargeItemList;
	}

}
